const htmlFileTemplate = 
`<div id='body'>hello world!</div>`;

const jsFileTemplate = 
`(({config,server,helper,components,CONST} = vinculum)=>{
	let r = React;
	let rd = ReactDOM;
	let imgPath = config.CDNImagePath + config.appname + '/';
	let mediaPath = config.CDNMediaPath + config.appname + '/';
	let imgCommonPath = config.CDNImagePath + 'common/';
	let mediaCommonPath = config.CDNMediaPath + 'common/';
	console.log('hello world!');
})(vinculum);`;

const cssFileTemplate = 
`.fun_shadow(@right:2px,@bottom:2px,@mohu:5px,@width:1px,@color:rgba(0,0,0,0.5)){
	box-shadow: @right @bottom @mohu @width @color;
	-moz-box-shadow: @right @bottom @mohu @width @color;
	-webkit-box-shadow: @right @bottom @mohu @width @color;
	-o-box-shadow: @right @bottom @mohu @width @color;
}`;

const fileTemplates = {
	html:htmlFileTemplate
	,js:jsFileTemplate
	,css:cssFileTemplate
}

const linktype = 'application';

if(!params.name){
  ret('应用名称不能为空！');
}else{
  if(params.name === 'login' || params.name === 'console'){
    ret('应用名称不能使用后台名称');
  }else{
    new service(`${CONST.TABLE_PREFIX}_application_browse`).invoke(params.name,params.name).then(result=>{
      if(result.length>0){
        ret('应用名称重复');
      }else{
				if(!params.main_html) params.main_html = htmlFileTemplate;
				if(!params.main_js) params.main_js = jsFileTemplate;
				if(!params.main_css) params.main_css = cssFileTemplate;
				if(!params.viewport){
					params.viewport = 'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no';
				}
        return new service(`${CONST.TABLE_PREFIX}_application_insert`).invoke(params);
      }
    })
    .then(result=>{
      ret(null,'应用新增成功！');
    }).catch(err=>{
      ret(err);
    });
  }
}
